<!--suppress ALL -->
<include file="./Template/header.html" />

<link rel="stylesheet" type="text/css" href="/Template/css/patientInfo.css">
<script type="text/javascript" src="/Template/js/amazeui.js"></script>
<script type="text/javascript">


    $(function() {

        //初始化页面配置
        initPage("患者基本资料");

        $("select[name=sex]").change(function() {
            var value = $(this).val();
            $(this).prev().val(value);
        });
        $("textarea").keypress(function(e) {
            if (e.which == 13) {
                return false;
            }
        });

        var app = new Vue({
            el: '#container',
            data: {
            },
            methods: {
                checkPatientInfo: function(){
                    var name = $("input[name=name]").val();
//                    var idNo = $("input[name=idNo]").val();
                    var workorderId = $("input[name=workorderId]").val();
                    var patientId = $("input[name=patientId]").val();

                    if(isNullOrEmpty(name)) {
                        return false;
                    }
//                    if(isNullOrEmpty(idNo)) {
//                        return false;
//                    }

                    $.ajax({
                        url:"/wechat/workorder/checkPatientInfo",
                        type:"post",
                        data:{
                            name: name,
//                            idNo: idNo,
                            workorderId: workorderId,
                        },
                        dataType:"JSON",
                        beforeSend:function(){
                            $("#loadingToast").show();
                        },
                        complete:function(){
                            $('#loadingToast').hide();
                        },
                        success:function(data){
                            if(data.code != 0) {
                                if(data.length != 0) {
                                    $(".hisInfo").show();
                                    $("select[name=hisInfo]").empty();
                                    $("select[name=hisInfo]").append("<option value='-1'>无</option>"); //为Select追加一个Option(下拉项)
                                    for (var i = 0; i < data.length; i++) {
                                        $("select[name=hisInfo]").append("<option value='" + data[i]["patient_id"] + "'>" + data[i]["patient_name"] + "(" + data[i]["update_time"] + ")" + "</option>"); //为Select追加一个Option(下拉项)
                                    }
                                }
                            }
//                            else{
//                                $("input[name=patientId]").val(null);
//                            }
                        },
                    })
                },
                cancel: function() {
                    window.location.href = "/wechat/workorder/index/id/{$workorderId}";
                },
                save: function() {
                    var patientId = $("input[name=patientId]").val();
                    var workorderId = $("input[name=workorderId]").val();
                    var name = $("input[name=name]").val();
                    var sex = $("select[name=sex]").val();
                    var age = $("input[name=age]").val();
                    var height = $("input[name=height]").val();
                    var weight = $("input[name=weight]").val();
                    var diagnosis = $("textarea[name=diagnosis]").val().replace(/[\r\n]/g,"");
                    var happenDate = $("input[name=happenDate]").val();
                    var idNo = $("input[name=idNo]").val();
                    var address = $("textarea[name=address]").val().replace(/[\r\n]/g,"");
                    var contact = $("input[name=contact]").val();
                    var mobile = $("input[name=mobile]").val();
                    var hospital = $("input[name=hospital]").val();
                    var doctor = $("input[name=doctor]").val();
                    var reason = $("input[name=reason]").val();
                    var compl = $("input[name=compl]").val();
                    var allergy = $("input[name=allergy]").val();
                    var oldOrth = $("input[name=oldOrth]").val();
                    var orthPart = $("input[name=orthPart]").val();
                    var history = $("input[name=history]").val();
                    var diagnosis1 = $("textarea[name=diagnosis1]").val().replace(/[\r\n]/g,"");
                    var diagnosis2 = $("textarea[name=diagnosis2]").val().replace(/[\r\n]/g,"");
                    var diagnosis3 = $("textarea[name=diagnosis3]").val().replace(/[\r\n]/g,"");
                    var diagnosis4 = $("textarea[name=diagnosis4]").val().replace(/[\r\n]/g,"");
                    var diagnosis5 = $("textarea[name=diagnosis5]").val().replace(/[\r\n]/g,"");

                    var completed = "1";

                    if(isNullOrEmpty(name)) {
                        completed = "-1";
                    }

                    if(isNullOrEmpty(sex)) {
                        completed = "-1";
                    }

                    if(isNullOrEmpty(age)) {
                        completed = "-1";
                    }

                    if(isNullOrEmpty(height)) {
                        completed = "-1";
                    }

                    if(isNullOrEmpty(weight)) {
                        completed = "-1";
                    }

                    if(isNullOrEmpty(diagnosis)) {
                        completed = "-1";
                    }

                    if(isNullOrEmpty(happenDate)) {
                        completed = "-1";
                    }

                    if(isNullOrEmpty(idNo)) {
                        completed = "-1";
                    }else{
                        if(idNo.length != 18) {
                            alert("身份证号位数不对");
                            return false;
                        }
                    }

                    if(isNullOrEmpty(address)) {
                        completed = "-1";
                    }

                    if(isNullOrEmpty(contact)) {
                        completed = "-1";
                    }

                    if(isNullOrEmpty(mobile)) {
                        completed = "-1";
                    }else{
                        if(!checkPhone(mobile)) {
                            alert("联系电话位数不对");
                            return false;
                        }
                    }

                    if("{$workorder.workorder_type}" == 2){
                        if(isNullOrEmpty(reason)) {
                            completed = "-1";
                        }
                        if(isNullOrEmpty(compl)) {
                            completed = "-1";
                        }
                        if(isNullOrEmpty(allergy)) {
                            completed = "-1";
                        }
                        if(isNullOrEmpty(oldOrth)) {
                            completed = "-1";
                        }
                        if(isNullOrEmpty(orthPart)) {
                            completed = "-1";
                        }
                        if(isNullOrEmpty(history)) {
                            completed = "-1";
                        }
                    }

                    $.ajax({
                        url:"/wechat/workorder/patientInfoPost",
                        type:"post",
                        data:{
                            patientId: patientId,
                            workorderId: workorderId,
                            completed:completed,
                            name: name,
                            sex: sex,
                            age: age,
                            height: height,
                            weight: weight,
                            diagnosis: diagnosis,
                            happenDate: happenDate,
                            idNo: idNo,
                            address: address,
                            contact: contact,
                            mobile: mobile,
                            hospital: hospital,
                            doctor: doctor,
                            reason: reason,
                            compl: compl,
                            allergy: allergy,
                            oldOrth: oldOrth,
                            orthPart: orthPart,
                            history: history,
                            diagnosis1: diagnosis1,
                            diagnosis2: diagnosis2,
                            diagnosis3: diagnosis3,
                            diagnosis4: diagnosis4,
                            diagnosis5: diagnosis5,
                        },
                        dataType:"JSON",
                        beforeSend:function(){
                            $("#loadingToast").show();
                        },
                        complete:function(){
                            $('#loadingToast').hide();
                        },
                        success:function(data){

                            if(data.code == 200) {
                                alert("保存成功");
                                window.location.href = "/wechat/workorder/index/id/{$workorderId}";
                            }
                        },
                    })

                }
            }
        })

        function getPatientInfo(id){
            var patientId = id;
            if(isNullOrEmpty(id)) {
                return false;
            }
            $.ajax({
                url:"/wechat/workorder/getPatientInfo",
                type:"post",
                data:{
                    patientId: patientId,
                },
                dataType:"JSON",
                beforeSend:function(){
                    $("#loadingToast").show();
                },
                complete:function(){
                    $('#loadingToast').hide();
                },
                success:function(data){
                    if(data.code == 200) {
                        $("select[name=sex]").val(data.sex);
                        $("input[name=idNo]").val(data.id_no);
                        $("input[name=age]").val(data.age);
                        $("input[name=height]").val(data.height);
                        $("input[name=weight]").val(data.weight);
                        $("textarea[name=diagnosis]").val(data.diagnosis);
                        $("input[name=happenDate]").val(data.happenDate);
                        $("textarea[name=address]").val(data.address);
                        $("input[name=contact]").val(data.contact);
                        $("input[name=mobile]").val(data.mobile);
                        $("input[name=hospital]").val(data.hospital);
                        $("input[name=doctor]").val(data.doctor);
                        $("input[name=reason]").val(data.reason);
                        $("input[name=compl]").val(data.compl);
                        $("input[name=allergy]").val(data.allergy);
                        $("input[name=oldOrth]").val(data.oldOrth);
                        $("input[name=orthPart]").val(data.orthPart);
                        $("input[name=history]").val(data.history);
                        $("textarea[name=diagnosis1]").val(data.diagnosis1);
                        $("textarea[name=diagnosis2]").val(data.diagnosis2);
                        $("textarea[name=diagnosis3]").val(data.diagnosis3);
                        $("textarea[name=diagnosis4]").val(data.diagnosis4);
                        $("textarea[name=diagnosis5]").val(data.diagnosis5);
                    }
//                            else{
//                                $("input[name=patientId]").val(null);
//                            }
                },
            })
        }
        $(".item select").change(function() {
            var value = $(this).find("option:selected").text();
            $(this).prev().val(value);
        });

        $("select[name=hisInfo]").change(function() {
            getPatientInfo($("select[name=hisInfo]").val())
        });


    })

</script>

<div class="container" id="container">
    <div class="hint-info">
        <span class="update_time">{$formDict.update_time}：{$patientInfo.update_time}</span>
        <span class="employee_name">{$formDict.update_name}：{$employeeName}</span>
    </div>
    <div class="edit-info">
        <div class="edit-content">
            <input type="text" style="display: none;" name="workorderId" value="{$workorderId}">
            <input type="text" style="display: none;" name="patientId" value="{$patientId}">
            <div class="item hisInfo" style="display: none;">
                <span>患者列表：</span>
                <input id="hisInfo" value="" type="text" readonly placeholder="请选择">
                <select name="hisInfo">
                    <option value="">请选择</option>
                </select>
                <img class="icon-right" src="/Template/images/icon-right.png" alt="">
            </div>
            <div class="item"><span>{$formDict.patient_name}：</span><input name="name" type="text" value="{$patientInfo.patient_name}" placeholder="请输入" v-on:blur="checkPatientInfo()"></div>
            <div class="item"><span>{$formDict.id_no}：</span><input name="idNo" type="text" value="{$patientInfo.id_no}" placeholder="请输入"></div>

            <div class="item"><span>{$formDict.age}：</span><input name="age" type="text" value="{$patientInfo.age}" placeholder="请输入"></div>
            <div class="item">
                <span>{$formDict.sex}：</span>
                <input id="sex" value="{$patientInfo.sex}" type="text" readonly placeholder="请选择">
                <select name="sex">
                    <option value="{$patientInfo.sex}"></option>
                    <if condition="$patientInfo['sex'] eq '男'">
                        <option value="男" selected="selected">男</option>
                        <else/>
                        <option value="男">男</option>
                    </if>

                    <if condition="$patientInfo['sex'] eq '女'">
                        <option value="女" selected="selected">女</option>
                        <else/>
                        <option value="女">女</option>
                    </if>
                </select>
            </div>
            <div class="item"><span>{$formDict.height}：</span><input name="height" type="text" value="{$patientInfo.height}" placeholder="请输入"></div>
            <div class="item"><span>{$formDict.weight}：</span><input name="weight" type="text" value="{$patientInfo.weight}" placeholder="请输入"></div>
            <div class="item">
                <span>{$formDict.diagnosis}：</span>
                <textarea class="t-area" name="diagnosis" maxlength="60" placeholder="请输入">{$patientInfo.diagnosis}</textarea>
            </div>
            <div class="item"><span>功能障碍发生时间：</span><input style="width: 32%;" name="happenDate" type="text" value="{$patientInfo.happen_date}" placeholder="请输入"></div>
            <div v-if="{$workorder.workorder_type} == 2">
                <div class="item"><span>功能障碍原因：</span><input style="width: 52%;" name="reason" type="text" value="{$patientInfo.reason}" placeholder="请输入"></div>
                <div class="item"><span>合并症情况：</span><input name="compl" type="text" value="{$patientInfo.compl}" placeholder="请输入"></div>
                <div class="item"><span>材料过敏史：</span><input name="allergy" type="text" value="{$patientInfo.allergy}" placeholder="请输入"></div>
                <div class="item"><span>既往矫形器：</span><input name="oldOrth" type="text" value="{$patientInfo.old_orth}" placeholder="请输入"></div>
                <div class="item"><span>矫正部位：</span><input name="orthPart" type="text" value="{$patientInfo.orth_part}" placeholder="请输入"></div>
                <div class="item"><span>病史：</span><input name="history" type="text" value="{$patientInfo.history}" placeholder="现病史、既往病史、家族病史"></div>
            </div>

            <div class="item">
                <span>{$formDict.address}：</span>
                <textarea class="t-area" name="address" maxlength="60" placeholder="请输入">{$patientInfo.address}</textarea>
            </div>
            <div class="item"><span>{$formDict.contact}：</span><input name="contact" type="text" value="{$patientInfo.contact}" placeholder="请输入"></div>
            <div class="item"><span>{$formDict.mobile}：</span><input name="mobile" type="text" value="{$patientInfo.mobile}" placeholder="请输入"></div>
            <div class="item"><span>就诊医院：</span><input name="hospital" type="text" value="{$patientInfo.hospital}" placeholder="请输入"></div>
            <div class="item"><span>医生：</span><input name="doctor" type="text" value="{$patientInfo.doctor}" placeholder="请输入"></div>
            <div class="item">
                <span>功能障碍/畸形诊断：</span>
                <textarea class="t-area" name="diagnosis1" maxlength="60" placeholder="请输入">{$patientInfo.diagnosis1}</textarea>
            </div>
            <div class="item">
                <span>x光片发现：</span>
                <textarea class="t-area" name="diagnosis2" maxlength="60" placeholder="请输入">{$patientInfo.diagnosis2}</textarea>
            </div>
            <div class="item">
                <span>CT发现：</span>
                <textarea class="t-area" name="diagnosis3" maxlength="60" placeholder="请输入">{$patientInfo.diagnosis3}</textarea>
            </div>
            <div class="item">
                <span>MRI发现：</span>
                <textarea class="t-area" name="diagnosis4" maxlength="60" placeholder="请输入">{$patientInfo.diagnosis4}</textarea>
            </div>
            <div class="item">
                <span>发病史、治疗史、支具史：</span>
                <textarea class="t-area" name="diagnosis5" maxlength="60" placeholder="请输入">{$patientInfo.diagnosis5}</textarea>
            </div>

            <div class="line"></div>
        </div>
    </div>
    <div class="operation-btn">
        <div class="cancle-btn" v-on:click="cancel">取消</div>
        <if condition="$workorder['status'] lt '2' && $workorder['creator_id'] eq $customerId">
            <div class="save-btn" v-on:click="save">保存</div>
        </if>
        <if condition="$workorder['status'] gt '-1' && $job[0] eq 100">
            <div class="save-btn" v-on:click="save">保存</div>
        </if>
    </div>
</div>
<include file="./Template/footer.html" />